﻿using MyLeetCode.Data;

public partial class Solution
{
    public ListNode ReverseList(ListNode head)
    {
        // 双指针迭代法
        ListNode prev = null;
        ListNode node = head;
        while (node != null)
        {
            // 每次将node.next指向prev
            // 然后node和prev向后移动一次
            ListNode temp = node.Next;
            node.Next = prev;
            prev = node;
            node = temp;
        }
        return prev;
    }
}
